package com.wowangz.cms.syscore.utils;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.context.ApplicationContext;

public class MessageResourcesUtils {
	
	//获取资源文件
	public static String getMessage(HttpServletRequest request, String key) {
		
		ApplicationContext applicationContext = SpringUtil.getApplicationContext();
		
		Locale locale  =  Locale.CHINA;
		HttpSession sessioin=request.getSession();
		String language=null;
		if(sessioin.getAttribute("com.iss.language")!=null){
			language=(String)sessioin.getAttribute("com.iss.language");
		}
		if(language==null||language.equals("zh_CN")){
			locale=Locale.CHINA;
		}
		else{
			if(language.equals("en_US")){
				locale=Locale.US;
			}
			else if(language.equals("ja-JP")){
				locale=Locale.JAPAN;
			}
			else if(language.equals("ko-KR")){
				locale=Locale.KOREA;
			}
		}
		String returnMessage="";
		try{
			returnMessage=applicationContext.getMessage(key, null, locale);
			returnMessage=returnMessage.replace("'", "’");//英文国际化特殊字符兼容JQUERY代码
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
		return returnMessage;
	}

}
